<?php
require_once dirname(__FILE__) . '/../common.inc.php';
try {
  $hostname = DB_HOST;
  $username = DB_LOGIN;
  $password = DB_PASS;
  $dbname = DB_NAME;
  $myPdo = new PDO ('mysql:host=' . $hostname, $username, $password);
  $myPdo->exec('USE ' . $dbname);
  $myPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_category`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `parent_id` int,
           `name` varchar(64),
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_customer`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `date_added` datetime,
           `date_last_mod` datetime,
           `email` varchar(64) UNIQUE,
           `password` varchar(64),
           `name` varchar(128),
           `mob` varchar(32),
           `tel` varchar(32),
           `reg_ip` varchar(32),
           `pw_question` varchar(256),
           `pw_answer` varchar(256),
           `status` tinyint(1),
           `company_name` varchar(64),
           `link_blog` varchar(64),
           `link_web` varchar(64),
           `country` varchar(64),
           `perc_of_use` varchar(64),
           `no_of_weds` varchar(64),
           `how_hear_us` varchar(64),
           `access_to_forum` tinyint(1),
           `send_price_list` tinyint(1),
           `phone_me` tinyint(1),
           `we_need_know` varchar(1024),
           `help_now` varchar(1024)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_customer_address`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `customer_track_id` varchar(16),
           `name` varchar(128),
           `tel` varchar(32),
           `mob` varchar(32),
           `address` varchar(1024),
           `suburb` varchar(64),
           `city` varchar(64),
           `state` varchar(64),
           `country` varchar(64),
           `zip` varchar(16),
           `is_default` tinyint(1),
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_customer_image`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `customer_track_id` varchar(16),
           `name` varchar(128),
           `name_on_server` varchar(64),
           `size` float,
           `width` float,
           `height` float,
           `path` varchar(512),
           `path_tn` varchar(512),
           `is_default` tinyint(1)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_mthd_payment`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(128) UNIQUE,
           `intro_brief` text,
           `status` tinyint(1),
           `is_offline` tinyint(1),
           `is_custom` tinyint(1),
           `folder` varchar(64) UNIQUE,
           `width` int,
           `height` int,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_mthd_shipping`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(128) UNIQUE,
           `intro_brief` text,
           `total` decimal(10, 2),
           `status` tinyint(1),
           `is_custom` tinyint(1),
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_order`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `date_added` datetime,
           `date_last_mod` datetime,
           `customer_id` int,
           `order_no` varchar(64),
           `is_paid` tinyint(1),
           `is_shipped` tinyint(1),
           `total` decimal(10, 2),
           `ip` varchar(32),
           `cc_email` varchar(64),
           `comment` text,
           `payment_id` int,
           `payment_name` varchar(128),
           `transaction_id` int,
           `parcel_id` int,
           `ship_id` int,
           `ship_name` varchar(128),
           `ship_total` decimal(10, 2),
           `addr_id` int,
           `addr_name` varchar(128),
           `addr_tel` varchar(32),
           `addr_mob` varchar(32),
           `addr_address` varchar(1024),
           `addr_suburb` varchar(64),
           `addr_city` varchar(64),
           `addr_state` varchar(64),
           `addr_country` varchar(64),
           `addr_zip` varchar(16)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_parcel`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `date_added` datetime,
           `date_last_mod` datetime,
           `date_delivery` datetime,
           `addr_id` int,
           `addr_name` varchar(128),
           `addr_tel` varchar(32),
           `addr_mob` varchar(32),
           `addr_address` varchar(1024),
           `addr_suburb` varchar(64),
           `addr_city` varchar(64),
           `addr_state` varchar(64),
           `addr_country` varchar(64),
           `addr_zip` varchar(16),
           `ship_id` int,
           `ship_name` varchar(128),
           `track_no` varchar(64),
           `weight` decimal(8,3),
           `comment` text
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_product`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `date_added` datetime,
           `date_last_mod` datetime,
           `category_id` int,
           `model_id` int,
           `name` varchar(64),
           `price` decimal(10, 2),
           `stock` int,
           `status` tinyint(1),
           `ship_req` tinyint(1),
           `intro_brief` text,
           `intro_detail` text,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_product_attribute`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `product_track_id` varchar(16),
           `name` varchar(64),
           `type` smallint,
           `is_mandatory` tinyint(1),
           `intro_brief` text,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_product_image`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `product_track_id` varchar(16),
           `name` varchar(128),
           `name_on_server` varchar(64),
           `size` float,
           `width` float,
           `height` float,
           `path` varchar(512),
           `path_small` varchar(512),
           `path_tn` varchar(512),
           `is_default` tinyint(1)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_product_option`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `attribute_id` int,
           `name` varchar(64),
           `tag` varchar(64),
           `price` decimal(10, 2),
           `intro_brief` text,
           `is_default` tinyint(1),
           `image_path` varchar(512),
           `image_path_small` varchar(512),
           `image_path_tn` varchar(512),
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_purchase`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `date_added` datetime,
           `date_last_mod` datetime,
           `customer_id` int,
           `order_id` int,
           `product_id` int,
           `name` varchar(64),
           `price` decimal(10, 2),
           `quantity` smallint,
           `total` decimal(10, 2),
           `ship_req` tinyint(1)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_purchase_attribute`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `purchase_track_id` varchar(16),
           `attribute_id` int,
           `name` varchar(64),
           `type` smallint,
           `customer_input` varchar(64)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_purchase_option`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `attribute_track_id` varchar(16),
           `option_id` int,
           `name` varchar(64)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_ecom_transaction`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `date_added` datetime,
           `date_last_mod` datetime,
           `date_paid` datetime,
           `trans_no` varchar(64),
           `customer_id` int,
           `payment_id` int,
           `payment_name` varchar(128),
           `total` decimal(10, 2),
           `trans_ref` text,
           `is_custom` tinyint(1)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_menu`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `parent_id` int,
           `name` varchar(64),
           `subtitle` varchar(64),
           `is_default` bool,
           `appear_in_menu` bool,
           `url` char(128),
           `desc` text,
           `keywords` text,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_module`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(64) UNIQUE,
           `folder` varchar(64) UNIQUE,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_module_menu`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `module_track_id` varchar(16),
           `name` varchar(64),
           `arg` varchar(64)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_page`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `menu_id` int,
           `html` longtext,
           `css` longtext,
           `js` longtext
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_plugin`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(64) UNIQUE,
           `folder` varchar(64) UNIQUE,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_plugin_instance`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `menu_id` int,
           `plugin_id` int,
           `width` int,
           `height` int,
           `scrolling` tinyint(1)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_profile`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `account` varchar(16) UNIQUE,
           `password` varchar(64),
           `email` varchar(128),
           `title` text,
           `desc` text,
           `keywords` text,
           `mail_host` varchar(64),
           `mail_SMTPAuth` tinyint(1),
           `mail_account` varchar(64),
           `mail_password` varchar(64),
           `mail_from_mail` varchar(64),
           `mail_from_name` varchar(64),
           `theme_id` int,
           `analytics_code` varchar(64)
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  $sql = "CREATE TABLE IF NOT EXISTS `pz_theme`(
           `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
           `track_id` varchar(16) UNIQUE,
           `name` varchar(64) UNIQUE,
           `folder` varchar(64) UNIQUE,
           `order` double
          ) ENGINE=MYISAM;";
  $myPdo->exec($sql);
  echo 'Completed Successfully.';
} catch (PDOException $e) {
  echo ERROR_SIGN . $e->getMessage();
}
?>
